import { Component, OnInit } from '@angular/core';
import { GetOrginizationService } from '../../../../share/services/get-orginization.service';
import {GetRTDataByKKSCodesService} from '../../../../share/services/get-rtdata-by-kkscodes.service';
import { GroupModal } from '../../../../share/models/org-response-modal';
import {PowerColModel} from '../../../../share/models/kdm-response-model'
import {Location} from '@angular/common'
import {Router} from "@angular/router";

@Component({
  selector: 'app-group-overview',
  templateUrl: './group-overview.component.html',
  styleUrls: ['./group-overview.component.css','../../../../share/css/button.css']
})
export class GroupOverviewComponent implements OnInit {

  orgList: GroupModal[] =[];
  totalKks:string;
  time:string='month'
  public staticTime:number = 1
  public startTime:string=""
  public endTime:string=""
  public id:number = 1
  capacity:number;
  public ymax:any
  public colDatas:PowerColModel[]
  public itemName:any[];
  public zhuangkuang:Array<any> = [{
      name: '较差',
      y: 1,
      color:'red'
    }, {
      name: '一般',
      y: 1,
      color:'yellow'
    }, {
      name: '良好',
      y: 1,
      color:'green'
    }]
  public zhuangkuang1:Array<any> = [{
      name: '正常',
      y: 1,
      color:'#3ec222'
    }, {
      name: '预警',
      y: 1,
      color:'#fcc81d'
    }, {
      name: '报警',
      y: 1,
      color:'#ed4227'
    }]
  public zhuangkuang2:Array<any> = [{
      name: '不健康',
      y: 1,
      color:'red'
    }, {
      name: '亚健康',
      y: 1,
      color:'yellow'
    }, {
      name: '健康',
      y: 1,
      color:'green'
    }]
  cap_en: any;
  constructor(
    private getOrg:GetOrginizationService,
    private getPowerColum:GetRTDataByKKSCodesService,
    private location:Location,
    private router: Router
  ) { }

  ngOnInit() {
    this.initOrgPanel()
  }
  initOrgPanel(){
    this.totalKks='HDZ00W00';
    this.getOrg.getOrg().subscribe(
      res=>{
        let ca=0;
        res.forEach(a=>{
          if(a.stationSet){
            a.stationSet.forEach(b=>{
              if(b.wtSet){
                b.wtSet.forEach(c=>{
                  ca+=c.capacity;
                })
              }
            })
          }
        })
        this.capacity=ca;
        res.forEach(it=>{
          if(it.stationSet){
            this.orgList.push(it);
          }
        })
        this.orgList.forEach(function (e) {
          e.routerLink=['/pages/cockpit/regional-overview', e.id];
          switch (e.nameForShort){
            case  '蒙东': e.imgUrl="/assets/images/old/logos/mengdong.gif";break;
            case  '蒙西': e.imgUrl="/assets/images/old/logos/mengxi.gif";break;
            default:break;
          }
        })
      }
    )
    this.getPowerColum.getPowerColum(this.id,this.staticTime)
      .subscribe(
        data=>{
          this.colDatas=data;
          // console.log(data)
          let capacity=[],energy=[];
          let max=0;
          this.itemName=[]
          this.colDatas.forEach(elem=>{
            if(elem.id!==2){
              this.itemName.push(elem.name)
              capacity.push(elem.capacity/10000);
              energy.push(elem.energy/10000);
            }
          });
          this.ymax=max;
          this.cap_en=[
            { name: '发电量', data:energy, color: 'rgba(186,60,61,1)', pointPadding: 0.1,},
            { name: '装机容量', data:capacity,color: 'rgba(248,161,63,.9)' ,pointPadding: 0.05, yAxis: 1}
          ];
        }
      )
  }
  public goBack(flag?:boolean){
    if(flag){
      this.location.back()
    }
    else {
      this.router.navigate(['/pages/home'])
    }
  }
}
